package ac.svn.accesscontrol.ui.panel;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LayoutManager;
import java.awt.Paint;
import java.awt.RadialGradientPaint;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Point2D;
import java.awt.geom.RoundRectangle2D;

import javax.swing.JPanel;

public class RPanel extends JPanel {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private int xLoc = 0 , yLoc =  0;

    Color light = new Color(0xCAE1FF);//CAE1FF
    Color dark  = new Color(0xA2B5CD); //A2B5CD	

    public RPanel() 
    {
	super();
	addPainter();
    }

    public RPanel(LayoutManager layout) {
	super(layout);
	addPainter();
    }

    public RPanel(boolean isDoubleBuffered) {
	super(isDoubleBuffered);
	addPainter();
    }

    public RPanel(LayoutManager layout, boolean isDoubleBuffered) {
	super(layout, isDoubleBuffered);
	addPainter();
    }

    private void addPainter() {
	addMouseListener(new MouseListener() {
	    @Override
	    public void mouseReleased(MouseEvent e) {
		repaint();
	    }
	    @Override
	    public void mousePressed(MouseEvent e) {
		repaint();
	    }
	    @Override
	    public void mouseExited(MouseEvent e) {
		//dark = dark.brighter();
		repaint();
	    }
	    @Override
	    public void mouseEntered(MouseEvent e) {
		//dark = dark.darker();
		repaint();
	    }
	    @Override
	    public void mouseClicked(MouseEvent e) {
	    }
	});


	addMouseMotionListener(new MouseMotionListener() {
	    @Override
	    public void mouseMoved(MouseEvent e) {
		xLoc = e.getX();
		yLoc = e.getY();
		repaint();
	    }
	    @Override
	    public void mouseDragged(MouseEvent e) {
	    }
	});	
    }

    //@Override
    protected void paintComponentD(Graphics g) {
	super.paintComponent(g);
	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	Paint oldPaint = g2.getPaint();
	g2.setColor(Color.GREEN);
	Paint radical = new RadialGradientPaint(new Point2D.Double(xLoc,yLoc), getWidth()/2,
		new float[] { 0.0f, 0.5f ,1.0f },
		new Color[] {light.brighter(),dark,dark.darker()});
	g2.setPaint(radical);

	g2.fill(new RoundRectangle2D.Double(0,0,getWidth(),getHeight(),5,5));
	g2.setPaint(oldPaint);
	
    }


}
